﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.Unity;

using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Presentation.Events;

namespace EQual.MainModule
{
    public class MainController
    {
        IEventAggregator eventAggregator;
        IUnityContainer container;

        public MainController(IEventAggregator eventAggregator,IUnityContainer container  )
        {
            this.eventAggregator = eventAggregator;
            this.container = container;
        }

        public void ActivateModuleController(EQual.Infrastructure.IModuleController controller)
        {
            controller.Run();
        }

        //this is bullshit and must finaly replaced by polymorphism on controllers
        public void DispalyView(string view)
        {
            if (view == "Εγγραφα")
                container.Resolve<EQual.MainModule.Documents.Presenters.IDocumentsController>().Run();
            if (view == "Εργαζομενοι")
                container.Resolve<EQual.MainModule.Employees.Presenters.IEmployeesController>().Run();
            if (view == "Λίστα Ενέργειών")
                container.Resolve<EQual.MainModule.Projects.Presenters.ProjectsController>().Run();
            if (view == "Συμβούλια")
                container.Resolve<EQual.MainModule.Reviews.Presenters.ReviewsController>().Run();
            if (view == "Συμβούλια")
                container.Resolve<EQual.MainModule.Reviews.Presenters.ReviewsController>().Run();
            if (view == "Εκπαιδευσεις")
                container.Resolve<EQual.MainModule.Employees.Trainings.TrainingsController>().Run();
            if (view == "Εντυπα")
                container.Resolve<EQual.MainModule.Documents.Forms.FormsController>().Run();
            if (view == "Παράπονα")
                container.Resolve<EQual.MainModule.QualityEvents.QualityComplaintsController>().Run();
            if (view == "Μη Συμόρφωση")
                container.Resolve<EQual.MainModule.QualityEvents.QualityNonConformitiesController>().Run();
            if (view == "Αιτήσεις εκπαιδευσης")
                container.Resolve<EQual.MainModule.Employees.Proposals.ProposalsController>().Run();
        }

        public void Run()
        {
            WpfApplicationExperimental.Login login = new WpfApplicationExperimental.Login();
            login.ShowDialog();

            eventAggregator.GetEvent<EQual.Infrastructure.NavigationViewSelected>().Subscribe(DispalyView, ThreadOption.UIThread, true);
        }

    }
}
